import pygame
import sys

from zuoye2.人人对战 import pvp_game
from zuoye2.人机对战 import pvc_game

# 游戏配置
WIDTH = 800
HEIGHT = 600
BUTTON_WIDTH = 200
BUTTON_HEIGHT = 50

# 初始化Pygame
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("五子棋")

# 加载背景图片
background_image = pygame.image.load("background.jpg")  # 替换为你的背景图片路径

# 加载字体
font = pygame.font.Font('D:/demo/ziti/DuanNingMaoBiXiaoKai/DuanNingMaoBiXiaoKai-2.ttf', 48)


# 游戏开始页面
def start_page():
    screen.blit(background_image, (0, 0))  # 绘制背景图片

    # 绘制五子棋题目
    title_text = font.render("五子棋", True, (255, 255, 255))
    title_rect = title_text.get_rect(center=(WIDTH // 2, HEIGHT // 2 - 100))
    screen.blit(title_text, title_rect)

    # 绘制人人对战按钮
    pvp_button_rect = pygame.Rect(WIDTH // 2 - BUTTON_WIDTH // 2, HEIGHT // 2, BUTTON_WIDTH, BUTTON_HEIGHT)
    pygame.draw.rect(screen, (0, 255, 0), pvp_button_rect)
    pvp_text = font.render("人人对战", True, (0, 0, 0))
    pvp_text_rect = pvp_text.get_rect(center=pvp_button_rect.center)
    screen.blit(pvp_text, pvp_text_rect)

    # 绘制人机对战按钮
    pvc_button_rect = pygame.Rect(WIDTH // 2 - BUTTON_WIDTH // 2, HEIGHT // 2 + BUTTON_HEIGHT + 10, BUTTON_WIDTH,
                                  BUTTON_HEIGHT)
    pygame.draw.rect(screen, (255, 0, 0), pvc_button_rect)
    pvc_text = font.render("人机对战", True, (0, 0, 0))
    pvc_text_rect = pvc_text.get_rect(center=pvc_button_rect.center)
    screen.blit(pvc_text, pvc_text_rect)

    pygame.display.flip()

    # 事件处理
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 1:
                    mouse_pos = event.pos
                    if pvp_button_rect.collidepoint(mouse_pos):  # 点击了人人对战按钮
                        # 进入人人对战页面
                        pvp_game_page()
                    elif pvc_button_rect.collidepoint(mouse_pos):  # 点击了人机对战按钮
                        # 进入人机对战页面
                        pvc_game_page()


# 人人对战页面
def pvp_game_page():
    # 在这里实现人人对战的逻辑，可以是调用其他函数或者类来完成
    pvp_game()
    pass


# 人机对战页面
def pvc_game_page():
    # 在这里实现人机对战的逻辑，可以是调用其他函数或者类来完成
    pvc_game()
    pass


# 运行游戏开始页面
start_page()
